#ifndef _CURVE_H_
#define _CURVE_H_
#include "Spline.h"


//dim维曲线拟合
template <int dim>
class Curve{
public:
    vector<PPSpline> ppspline_fit;
    // PPSpline Bxs;
    // PPSpline Bys;
    BCT bct = complete;
    double Curve_S;

    // 计算两点在n维空间中的距离  
    double distance(const std::vector<double>& point1, const std::vector<double>& point2) {  
        if (point1.size() != point2.size()) {  
            // 处理维度不匹配的情况  
            return -1;  
        }  
    
        double sum = 0.0;  
        for (size_t i = 0; i < point1.size(); ++i) {  
            double diff = point1[i] - point2[i];  
            sum += diff * diff;  
        }  
        return std::sqrt(sum);  
    } 
    

    Curve(const vector<vector<double>> &knots,const vector<vector<double>> &bcts,BCT bct)
        :bct(bct){
        if(knots.size() != dim){
            error("dim is wrong");
        }

        vector<double >s;
        vector<double> tmp2;
        double d=0;
        for(int i=0;i<knots[0].size();i++){
            vector<double> tmp1;
            for(int j=0;j<knots.size();++j){
                tmp1.push_back(knots[j][i]);
            }  
            if(i==0){
                tmp2=tmp1;
            }
            d+=distance(tmp1,tmp2);
            s.push_back(d);
            tmp2 = tmp1;
        }
        Curve_S = s.back();
        for(int i=0;i<knots.size();i++){
            if(s.size()!=knots[i].size()){
                error("dim is wrong");
            }
            ppspline_fit.push_back(PPSpline(s,knots[i],bct,bcts[i][0],bcts[i][1]));
        }
    }
};

#endif